package com.aso114.project.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.base.BaseApplication;
import com.aso114.project.bean.QuestionBaseBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AnswerCardAdapter extends BaseAdapter {


    private Context mContext = null;
    ArrayList<QuestionBaseBean> baseBean;
    public AnswerCardAdapter(Context context, ArrayList<QuestionBaseBean> baseBean) {

        mContext = context;
        this.baseBean = baseBean;
    }

    @Override
    public int getCount() {
        return baseBean.size();
    }

    @Override
    public Object getItem(int i) {
        return baseBean.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AnswerCardAdapter.ViewHolder holder = null;
        if (convertView != null) {
            holder = (AnswerCardAdapter.ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getBaseContext()).inflate(R.layout.circle_img, parent, false);
            holder = new AnswerCardAdapter.ViewHolder(convertView);
            convertView.setTag(holder);
        }

//        if(position==2){
//            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_green));
//            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.white));
//        }
//        if(position==5){
//            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_green));
//        }
//        if(position==6){
//            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_green));
//            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.white));
//        }
//
//        if(position==8){
//            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_green));
//            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.white));
//        }
//
//        if(position==10){
//            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_circle));
//        }
//
//
//        if(position==12){
//            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_circle));
//            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.color_gray));
//        }
        //名称
        holder.tvName.setText((position + 1) + "");


        if (!baseBean.get(position).isFinishAnswer()) {//判断该题是否已经作答
//            viewHolder.tv.setBackgroundResource(R.drawable.circle_default);

            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_default));
            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.a333333));
        } else {//已经作答

            holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_red));

//            if (baseBean.get(position).isChooseResult()) {//判断选择的结果是否正确
//                holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_right));
//            } else {
//                holder.tvName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.circle_error));
//            }
        }

        return convertView;
    }

    static class ViewHolder {

        @BindView(R.id.circle_img)
        TextView tvName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}